﻿namespace LiSAClient.Core.Converters
{
    using System;
    using System.Globalization;
    using System.Windows;
    using System.Windows.Data;

    [ValueConversion(typeof(object), typeof(Visibility))]
    public class ValueCompareToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object expectedValue, CultureInfo culture)
        {
            if (value == null || expectedValue == null)
            {
                return Visibility.Collapsed;
            }

            if (value.GetType() == expectedValue.GetType())
            {
                var val1 = value as IComparable;
                var val2 = expectedValue as IComparable;

                if (val1 != null && val2 != null && val1.CompareTo(val2) == 0)
                {
                    return Visibility.Visible;
                }
            }

            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object expectedType, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
